//
//  String+Pred.swift
//  TTCOM
//
//  Created by Toj on 4/6/23.
//

import Foundation

/*
 * 谓语匹配
 */
public extension String {
    
    /** 验证只能是数字 */
    var pred_isValidNumber: Bool {
        let regex = "^[0-9]+$"
        let predicate = NSPredicate(format: "SELF MATCHES %@", regex)
        return predicate.evaluate(with: self)
    }
}

/*
// 谓词匹配是否为全中文
- (BOOL)validateAllChinese:(NSString *)content
{
    NSString *regEx = @"^[\u4e00-\u9fa5]+$";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx];
    
    return [predicate evaluateWithObject:content];
}

// 谓词匹配包含中文
- (BOOL)validateContainsChineseT:(NSString *)content
{
    NSString *regEx = @".+[\u4e00-\u9fa5].+";  // @"^[\u4e00-\u9fa5].*" - ^为匹配中文开始
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx];
    
    return [predicate evaluateWithObject:content];
}
*/
